/*
 * @Author: your name
 * @Date: 2021-08-25 11:37:11
 * @LastEditTime: 2021-08-27 09:29:31
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: /backend/src/main/java/com/buaa/demo/Controller/EmailController.java
 */
package com.buaa.demo.Controller;

import com.buaa.demo.Entity.User;
import com.buaa.demo.Service.MailService;
import com.buaa.demo.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@CrossOrigin
@RestController
public class EmailController {
    @Autowired
    private UserService userService;

    @Autowired
    private MailService mailService;

    @PostMapping("/verify")

    public Map<String, Object> verifyFunc(@RequestBody Map<String, String> remap){
        Map<String, Object> map = new HashMap<>();
        StaticPrint.printArgs("Send Verify Code", remap);
        try{
            mailService.sendSimpleMail(remap.get("email"), "ATBS ：请查收您的验证码", remap.get("reason"), remap.get("verify_code"));
            map.put("res", true);
            map.put("message", "验证码已发送，请查收");
        } catch(Exception e){
            e.printStackTrace();
            map.put("res", false);
            map.put("message", "验证码发送失败失败，请再次检查邮箱输入，并联系管理员解决。");
        }
        return map;
    }
}
